package com.lbmb.mdps.workbench.service.impl;

import com.lbmb.mdps.commons.domain.MedicineTypeVo;
import com.lbmb.mdps.commons.domain.SupplierReceive;
import com.lbmb.mdps.commons.domain.SupplierVo;
import com.lbmb.mdps.commons.exception.SupplierException;
import com.lbmb.mdps.workbench.dao.SupplierDao;
import com.lbmb.mdps.workbench.domain.MedicineType;
import com.lbmb.mdps.workbench.domain.Supplier;
import com.lbmb.mdps.workbench.service.SupplierService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 林文塨
 * @date 2022-05-30 23:12
 * description
 */
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {

    @Resource
    private SupplierDao supplierDao;

    @Override
    public List<Supplier> supplierPageList(SupplierReceive supplierReceive) throws SupplierException {
        /*
         * 分页获取供应商表功能
         * @author 林文塨
         * @date 2022/5/30 10:24
         * @param [employeeReceive]
         * @return java.util.List<com.lbmb.mdps.settings.domain.Employee>
         */
        List<Supplier> supplierList = supplierDao.supplierPageList(supplierReceive);

        if (supplierList == null) {
            throw new SupplierException("分页获取供应商列表失败！");
        }

        return supplierList;
    }

    @Override
    public Integer getSupplierTotal(SupplierReceive supplierReceive) throws SupplierException {
        /*
         * 获取供应商分页总条数功能
         * @author 林文塨
         * @date 2022/5/30 10:42
         * @param [employeeReceive]
         * @return java.lang.Integer
         */
        Integer total = supplierDao.getSupplierTotal(supplierReceive);

        if (total < 0) {
            throw new SupplierException("获取供应商分页总条数失败！");
        }

        return total;
    }

    @Override
    public void addSupplier(Supplier supplier) throws SupplierException {
        /*
         * 添加供应商
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = supplierDao.addSupplier(supplier);

        if (result != 1) {
            throw new SupplierException("添加供应商失败！");
        }
    }

    @Override
    public void editSupplier(Supplier supplier) throws SupplierException {
        /*
         * 修改供应商
         * @author 林文塨
         * @date 2022/5/30 13:06
         * @param [employee]
         * @return void
         */
        int result = supplierDao.editSupplier(supplier);

        if (result != 1) {
            throw new SupplierException("修改供应商失败！");
        }
    }

    @Override
    public void deleteSupplier(String[] deleteSupplierIds) throws SupplierException {
        /*
         * 删除供应商
         * @author 林文塨
         * @date 2022/5/30 16:32
         * @param [deleteEmployeeIds]
         * @return void
         */
        int result = supplierDao.deleteSupplier(deleteSupplierIds);

        if (result <= 0) {
            throw new SupplierException("删除供应商失败");
        }
    }

    @Override
    public List<SupplierVo> getAllSupplier() {
        /*
         * 获得全部供应商
         * @author 林文塨
         * @date 2022/6/1 1:24
         * @param []
         * @return java.util.List<com.lbmb.mdps.commons.domain.SupplierVo>
         */
        List<Supplier> supplierList = supplierDao.getAllSupplier();

        List<SupplierVo> supplierVoList = new ArrayList<>();

        for (Supplier supplier : supplierList) {
            SupplierVo supplierVo = new SupplierVo();
            supplierVo.setLabel(supplier.getName());
            supplierVo.setValue(supplier.getId());

            supplierVoList.add(supplierVo);
        }

        return supplierVoList;
    }
}
